package com.coolwen.spring.aop.base;

/**
 * @author CoolWen
 * @version 2020-03-19 8:46
 */
public class CalFibonacciImpl implements ICalFibonacci {
    @Override
    public long calFibonacciByLoop(long n) {
        long n1 = 1;
        long n2 = 1;
        long n3 = 0;
        for (int i = 3; i <= n; i++) {
            n3 = n1 + n2;
            n1 = n2;
            n2 = n3;
        }
        return n3;
    }

    @Override
    public long calFibonacciByRecusion(long n) {
        if (n == 1 || n == 2) {
            return 1;
        }
        return calFibonacciByRecusion(n - 2) + calFibonacciByRecusion(n - 1);
    }

//    @Override
//    public long stat(int method, long n) {
//        long start = new Date().getTime();
//        if (method == 0)
//            calFibonacciByLoop(n);
//        if (method == 1)
//            calFibonacciByRecusion(n);
//        long end = new Date().getTime();
//        return end - start;
//    }
}
